import Axios from 'axios'

const baseURL = import.meta.env.VITE_BASE_API_URL

const request = Axios.create({
    baseURL: baseURL,
    timeout: 5000
})

request.interceptors.request.use(config => {
    return config
}, error => {
    return Promise.reject(error)
})

request.interceptors.response.use(response => {
    if (response.data.code && response.data.code !== 200) {
        return Promise.reject(response.data.message)
    }
    return response.data
}, error => {
    return Promise.reject(error)
})

export default request